/**
 * 家庭表管理初始化
 */
var Family = {
    id: "FamilyTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
Family.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
            {title: '家庭id', field: 'id', visible: true, align: 'center', valign: 'middle'},
            {title: '家庭名称', field: 'spare1', visible: true, align: 'center', valign: 'middle'},
            {title: '家庭类型', field: 'familykindid', visible: true, align: 'center', valign: 'middle'},
            {title: '创建人', field: 'createid', visible: true, align: 'center', valign: 'middle'},
            {title: '创建时间', field: 'createtime', visible: true, align: 'center', valign: 'middle'},
            // {title: '更新时间', field: 'updatetime', visible: true, align: 'center', valign: 'middle'},
            // {title: '更新人id', field: 'updateid', visible: true, align: 'center', valign: 'middle'},
            {title: '备注', field: 'remark', visible: true, align: 'center', valign: 'middle'},

            // {title: '空闲字段2', field: 'spare2', visible: true, align: 'center', valign: 'middle'},
            // {title: '空闲字段3', field: 'spare3', visible: true, align: 'center', valign: 'middle'}
    ];
};

/**
 * 检查是否选中
 */
Family.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Feng.info("请先选中表格中的某一记录！");
        return false;
    }else{
        Family.seItem = selected[0];
        return true;
    }
};

/**
 * 点击添加家庭表
 */
Family.openAddFamily = function () {

    var index = layer.open({
        type: 2,
        title: '创建新家庭',
        area: ['800px', '250px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/family/family_add'
    });
    this.layerIndex = index;
};

/**
 * 打开查看家庭表详情
 */
Family.openFamilyDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '家庭详情',
            area: ['800px', '420px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/family/family_update/' + Family.seItem.id
        });
        this.layerIndex = index;
    }
};

/**
 * 删除家庭表
 */
Family.delete = function () {
    if (this.check()) {
        var ajax = new $ax(Feng.ctxPath + "/family/delete", function (data) {
            Feng.success("删除成功!");
            Family.table.refresh();
        }, function (data) {
            Feng.error("删除失败!" + data.responseJSON.message + "!");
        });
        ajax.set("familyId",this.seItem.id);
        ajax.start();
    }
};

/**
 * 查询家庭表列表
 */
Family.search = function () {
    var queryData = {};
    queryData['condition'] = $("#condition").val();
    Family.table.refresh({query: queryData});
};

$(function () {
    var defaultColunms = Family.initColumn();
    var table = new BSTable(Family.id, "/family/list", defaultColunms);
    table.setPaginationType("server");
    Family.table = table.init();
});
